<template>
	<view>
		<view class="bg-main u-p-30 u-p-t-80">
			<view class="u-flex">
				<view class="u-m-r-20">
					<u-icon name="clock" size="80" color="#ffffff" v-if="form.state == '已出库'"></u-icon>
					<u-icon name="checkmark-circle" size="80" color="#ffffff" v-if="form.state == '已完结'"></u-icon>
					<u-icon name="close-circle" size="80" color="#ffffff" v-if="form.state == '已取消'"></u-icon>
				</view>
				<view class="u-flex-1">
					<view class="head-title u-m-b-10"><text class="u-font-bold u-font-36 white-text">{{form.state}}<!-- <text v-if="form.state == '已出库'">(待回录)</text> --></text></view>
					<view class="u-font-24" v-if="form.state == '已出库'"><text class="white-text">创建出库单时间为{{form.createddatetime}}</text></view>
					<view class="u-font-24" v-if="form.state == '已完结'"><text class="white-text">完结时间为 {{form.endtime}}</text></view>
					<view class="u-font-24" v-if="form.state == '已取消'"><text class="white-text">取消时间为 {{form.endtime}}</text></view>
				</view>
			</view>
		</view>
		<!-- 出库站点 至 接收站点 -->
		<view class="grid-box">
			<view class="u-border-bottom u-m-b-20 u-p-b-20 ">
				<view class=""><text class="tips-txt u-font-28">{{form.number}}</text></view>
				<view><text class="u-font-24 u-tips-color">由<text class="bold-txt">{{form.staff.name}}</text>创建</text></view>
			</view>
			<view class="pack u-m-b-10">
				<view class="left-con">
					<view class="text in">出</view>
					<view class="border"></view>
					<view class="text" :class="form.manufacturer?'out':''">入</view>
				</view>
				<view class="u-flex u-p-l-20" :style="{'flex-direction': 'column','align-items': 'flex-start'}">
					<view class="item">
						<view>
							<!-- <view class="name" :class="item.state == '已取消'?'del-line':''" v-for="(item,index) in form.storeoutorder" :key="index">{{item.store.name}}<text v-if="item.state == '已取消'">(已撤销)</text></view> -->
							<view class="name">{{form.store.name}}</view>
							<view>
								<text class="text">站点</text>
							</view>
						</view>
					</view>
					<view class="item" :style="{'align-items':'flex-end'}" v-if="form.packinorder">
						<view>
							<view class="name">{{form.packinorder.packname}}</view>
							<view>
								<text class="text">类型：打包站</text>
							</view>
						</view>
					</view>
					<view class="item" :style="{'align-items':'flex-end'}" v-if="form.manufacturer">
						<view>
							<view class="name">{{form.manufacturer.name}}</view>
							<view>
								<text class="text">类型：厂商</text>
							</view>
						</view>
					</view>
				</view>
			</view>
			<view class="msg-box u-p-t-10 u-m-t-20 u-border-top" v-if="form.supercargo">
				<view class="item">
					<text class="label">负责人：</text>
					<view class="text left">{{form.supercargo.name}}</view>
				</view>	
			</view>
			<view class="msg-box" v-if="form.remarks">
				<view class="item">
					<text class="label">出库备注：</text>
					<view class="text left">{{form.remarks}}</view>
				</view>	
			</view>
		</view>
		<view class="box-link">
			<view class="cell"><view class="radius"></view><view class="line"></view><view class="radius"></view></view>
			<view class="cell"><view class="radius"></view><view class="line"></view><view class="radius"></view></view>
		</view>
		<!-- 已出库——显示站点出库的清单 -->
		<view class="grid-box">
			<view class="head-title u-m-b-10">
				<text>出库清单汇总</text>
				<text class="u-tips-color u-font-20">点击列查看详情</text>
			</view>
			<goods-table :details="confirmForm.details" :no-price="true" @tableClick="getTableDetails"></goods-table>
			<view class="dashed-line"></view>
			<view class="msg-box u-p-t-20 u-p-b-20">
				<view class="item">
					<text class="label">回收种类：</text>
					<view class="text left">共{{ confirmForm.details.length }}种</view>
				</view>
				<view class="item" v-if="form.weight > 0">
					<text class="label">出库总重：</text>
					<view class="text left">{{form.weight}}<text class="u-font-24">KG</text></view>
				</view>
				<view class="item" v-if="form.quantity > 0">
					<text class="label">出库总数：</text>
					<view class="text left">{{form.quantity}}<text class="u-font-24">件</text></view>
				</view>
			</view>
			
			<!-- 只有加盟商管理员或运营商管理员可查看的数据 -->
			<template v-if="form.ismanage">
				<view class="dashed-line"></view>
				<view class="msg-box u-p-b-20">
					<view class="item u-p-b-0">
						<text class="label">出库总成本</text>
						<view class="text total-price"><text class="u-font-24">￥</text><text class="u-font-32">{{ utils.formatMoney(form.cost) }}</text></view>
					</view>
					<view class="item u-p-b-0">
						<text class="label">预估销售金额</text>
						<view class="text total-price"><text class="u-font-24">￥</text><text class="u-font-32">{{ utils.formatMoney(form.amount) }}</text></view>
					</view>
					<view class="item u-p-b-0">
						<text class="label">估计利润</text>
						<view class="text total-price"><text class="u-font-24">￥</text><text class="u-font-32">{{ utils.formatMoney(form.profit) }}</text></view>
					</view>
				</view>
			</template>
			
			<!-- 上传图片 -->
			<view class="u-p-b-30" v-if="form.proves.length > 0">
				<view class="head-title u-m-b-30"><text>上传图片</text></view>
				<view class="upload-box u-m-b-10 u-m-t-10">
					<view class="item" v-for="(item, index) in form.proves" :key="index">
						<u-image width="200rpx" height="200rpx" :src="utils.getPic(item)" @click="seePhoto(item)">
						</u-image>
					</view>
				</view>
			</view>
			<!-- 备注 -->
			<view class="u-p-b-20" v-if="form.remarks">
				<view class="head-title u-m-b-10"><text>出库备注</text></view>
				<view class="u-p-t-20">
					<view style="padding: 10px;border-color: rgb(220, 223, 230);text-align: left;border-radius: 4px;border: 1px solid #dcdfe6;min-height: 62px;">{{form.remarks}}</view>
				</view>
			</view>
			<!-- <template>
				<view class="dashed-line"></view>
				<view class="u-p-t-30 u-p-b-30">
					<view class="head-title u-m-b-30"><text>查看各站点({{form.storeoutorder.length}}个)出库清单</text></view>
					<view 
						class="u-flex u-border-top u-border-bottom u-p-t-20 u-p-b-20" 
						v-for="(item,index) in form.storeoutorder" 
						:key="index" 
						@click="storeDetails(item)"
						:style="{'backgroundColor':item.state == '已取消'?'#f1f1f1':'#ffffff'}"
						>
						<view class="u-flex-1">
							<view class="u-p-b-10">
								<u-icon name="photo" v-if="item.proves.length > 0"></u-icon>
								<text>{{item.store.name}}</text>
							</view>
							<view>
								<text class="u-tips-color u-font-24">出库时间：{{item.endtime}}</text>
							</view>
						</view>
						<view class="u-p-r-5">
							<u-button type="error" size="mini" v-if="item.iscancel" @click="cancelOrder(item.id,`您确定要撤销${item.store.name}的出库单吗？`)">撤销</u-button>
							<text v-if="item.state == '已取消'">已撤销</text>
						</view>
						
						<u-icon name="arrow-right" class="u-tips-color" size="28"></u-icon>
					</view>
				</view>
			</template> -->
		</view>
		<!-- 已完结——核实出库 -->
		<template v-if="form.state == '已完结'">
			<view class="box-link">
				<view class="cell"><view class="radius"></view><view class="line"></view><view class="radius"></view></view>
				<view class="cell"><view class="radius"></view><view class="line"></view><view class="radius"></view></view>
			</view>
			<view class="grid-box">
				<view class="head-title u-m-b-10"><text>核实出库</text><text class="u-tips-color u-font-20">点击列查看详情</text></view>
				<goods-table :details="confirmOutOrderDetails" :head="['类型','可回收物','出库单价','出库总量','出库总价','操作']" @tableClick="tableClick"></goods-table>
				<view class="dashed-line"></view>
				<view class="msg-box u-p-t-20 u-p-b-20">
					<view class="item">
						<text class="label">出库种类：</text>
						<view class="text left">共{{ confirmOutOrderDetails.length }}种</view>
					</view>
					<view class="item" v-if="form.sellweight > 0">
						<text class="label">核实出库总重：</text>
						<view class="text left">{{form.sellweight}}KG</view>
					</view>
					<view class="item" v-if="form.sellquantity > 0">
						<text class="label">核实出库总数：</text>
						<view class="text left">{{form.sellquantity}}件</view>
					</view>
				</view>
				<!-- 只有加盟商管理员或运营商管理员可查看的数据 -->
				<template v-if="form.ismanage">
					<view class="dashed-line"></view>
					<view class="msg-box u-p-b-20">
						<view class="item u-p-b-0">
							<text class="label">售卖总金额</text>
							<view class="text total-price"><text class="u-font-24">￥</text><text class="u-font-32">{{ utils.formatMoney(form.sellamount) }}</text></view>
						</view>
						<view class="item u-p-b-0">
							<text class="label">售卖利润</text>
							<view class="text total-price"><text class="u-font-24">￥</text><text class="u-font-32">{{ utils.formatMoney(form.sellprofit) }}</text></view>
						</view>
					</view>
				</template>
				<view class="dashed-line"></view>
				<!-- 上传图片 -->
				<view class="u-p-t-30" v-if="form.proves.length > 0">
					<view class="head-title u-m-b-30"><text>上传图片</text></view>
					<view class="upload-box u-m-b-10 u-m-t-10">
						<view class="item" v-for="(item, index) in form.proves" :key="index">
							<u-image width="200rpx" height="200rpx" :src="utils.getPic(item)" @click="seePhoto(item)">
							</u-image>
						</view>
					</view>
				</view>
				<!-- <template>
					<view class="dashed-line"></view>
					<view class="u-p-t-30 u-p-b-30">
						<view class="head-title u-m-b-30"><text>查看各站点({{form.storeoutorder.length}}个)出库清单</text></view>
						<view 
							class="u-flex u-border-top u-border-bottom u-p-t-20 u-p-b-20" 
							v-for="(item,index) in form.storeoutorder" 
							:key="index" 
							@click="storeDetails(item)"
							:style="{'backgroundColor':item.state == '已取消'?'#f1f1f1':'#ffffff'}"
							>
							<view class="u-flex-1">
								<view class="u-p-b-10">
									<u-icon name="photo" v-if="item.proves.length > 0"></u-icon>
									<text>{{item.store.name}}</text>
								</view>
								<view>
									<text class="u-tips-color u-font-24">出库时间：{{item.endtime}}</text>
								</view>
							</view>
							<view class="u-p-r-5">
								<u-button type="error" size="mini" v-if="item.iscancel" @click="cancelOrder(item.id,`您确定要撤销${item.store.name}的出库单吗？`)">撤销</u-button>
								<text v-if="item.state == '已取消'">已撤销</text>
							</view>
							
							<u-icon name="arrow-right" class="u-tips-color" size="28"></u-icon>
						</view>
					</view>
				</template> -->
				<!-- 出库详情 -->
				<u-popup v-model="showPackdetails" mode="bottom" :closeable="true" border-radius="14" z-index="101">
					<view class="u-p-30 u-text-center">
						<text class="u-font-32">出库详情</text>
					</view>
					<u-cell-group>
						<u-cell-item title="类型" :arrow="false">{{packdetails.typenames}}</u-cell-item>
						<u-cell-item title="毛重(KG)" :arrow="false" v-if="packdetails.isweighing">{{packdetails.grossweight}}</u-cell-item>
						<u-cell-item title="皮重(KG)" :arrow="false" v-if="packdetails.isweighing">{{packdetails.tareweight}}</u-cell-item>
						<u-cell-item title="净重(KG)" :arrow="false" v-if="packdetails.isweighing">{{packdetails.netweight}}</u-cell-item>
						<u-cell-item title="数量(件)" :arrow="false" v-else>{{packdetails.netweight}}</u-cell-item>
						<u-cell-item title="扣重(KG)" :arrow="false" v-if="packdetails.isweighing">{{packdetails.deductionweight}}</u-cell-item>
						<u-cell-item title="扣点" :arrow="false" v-if="packdetails.isweighing">{{packdetails.deductionratio}}</u-cell-item>
						<u-cell-item :title="`单价(元/${packdetails.isweighing?'KG':'件'})`" :arrow="false">{{packdetails.price}}</u-cell-item>
						<u-cell-item title="金额(元)" :arrow="false">{{packdetails.amount}}</u-cell-item>
						<u-cell-item title="备注" :arrow="false">{{packdetails.typeremarks || '无'}}</u-cell-item>
					</u-cell-group>
				</u-popup>
			</view>
		</template>
		<!-- 已取消 -->
		<template v-if="form.state == '已取消'">
			<view class="box-link">
				<view class="cell"><view class="radius"></view><view class="line"></view><view class="radius"></view></view>
				<view class="cell"><view class="radius"></view><view class="line"></view><view class="radius"></view></view>
			</view>
			<view class="grid-box">
				<view class="head-title u-m-b-20"><text>取消原因</text></view>
				<view class="u-p-b-30">
					<u-input v-model="form.reason" type="textarea" :border="true" :disabled="true" />
				</view>
			</view>
		</template>
		<!-- 核实出库操作 -->
		<template v-if="form.isend">
			<view class="box-link">
				<view class="cell"><view class="radius"></view><view class="line"></view><view class="radius"></view></view>
				<view class="cell"><view class="radius"></view><view class="line"></view><view class="radius"></view></view>
			</view>
			<view class="grid-box">
				<!-- 添加回执单 -->
				<endOutboundList @getData="getEndOutboundList"></endOutboundList>
				<!-- 确认已入库时间 -->
				<view class="u-p-t-30">
					<view class="head-title u-m-b-10"><text>完结时间</text></view>
					<u-form :model="outOrderEndForm" ref="uForm" label-width="auto" :label-style="{'color':'#909399'}">
						<u-form-item label="选择时间:" required>
							<view class="input-text u-flex" style="width: 100%;" @click="chooseTime = true">
								<text>{{outOrderEndForm.endTime || '点击选择时间'}}</text>
								<view class="u-flex-1"></view>
								<u-icon name="arrow-right" class="tips-txt"></u-icon>
							</view>
						</u-form-item>
					</u-form>
					<!-- 选择入库时间 -->
					<u-picker v-model="chooseTime" mode="time" :params="params" @confirm="changeTime"></u-picker>
				</view>
				<!-- 上传图片 -->
				<view class="u-p-t-30">
					<view class="head-title u-m-b-10"><text>上传图片</text></view>
					<view class="upload-box">
						<view class="item">
							<common-upload max-count="9" @on-success="uploadSuccess" @on-remove="removePhoto"></common-upload>
						</view>
						<!-- <template v-else>
							<view class="item" v-for="(item,index) in form.qcpic" :key="index">
								<u-image width="200rpx" height="200rpx" :src="utils.getPic(item)" @click="seePhoto(item)"></u-image>
							</view>
						</template> -->
					</view>
				</view>
			</view>
		</template>
		
		<!-- 底部按钮 -->
		<view class="bottom-box">
			<view class="fixed-container">
				<view class="btn-group">
					<view class="u-flex">
						<view class="u-p-r-30" v-if="form.iscancel" @click="show1 = true"><text style="text-decoration: underline;">取消</text></view>
						<view class="u-flex-1">
							<u-button @click="back">返回</u-button>
						</view>
						<view class="u-flex-1" v-if="form.isend"><u-button type="primary" class="w-100" @click="confirmOutOrderEnd">结单</u-button></view>
					</view>
				</view>
			</view>
			<view class="fixed-placeholder"></view>
		</view>
		<!-- 出库汇总清单详情 -->
		<u-popup v-model="showTableDetails" mode="bottom" :closeable="true" border-radius="14" z-index="998">
			<view class="u-p-30 u-text-center">
				<text class="u-font-32">出库汇总清单详情</text>
			</view>
			<u-cell-group>
				<u-cell-item title="类型" :arrow="false">{{tableDetails.typenames}}</u-cell-item>
				<u-cell-item title="可回收物" :arrow="false">{{tableDetails.name}}</u-cell-item>
				<u-cell-item title="出库重量(KG)" :arrow="false" v-if="tableDetails.isweighing">{{tableDetails.weight}}</u-cell-item>
				<u-cell-item title="出库数量(件)" :arrow="false" v-else>{{tableDetails.weight}}</u-cell-item>
				<u-cell-item :title="`出库预估单价(元/${tableDetails.isweighing?'KG':'件'})`" :arrow="false">{{tableDetails.price}}</u-cell-item>
				<u-cell-item title="出库估值(元)" :arrow="false">{{tableDetails.amount}}</u-cell-item>
				<u-cell-item title="备注" :arrow="false">{{tableDetails.typeremarks || '无'}}</u-cell-item>
			</u-cell-group>
		</u-popup>
		<!-- 站点出库详情 -->
		<!-- <u-popup v-model="showStoreDetails" mode="bottom" :closeable="true" border-radius="14" z-index="998">
			<scroll-view class="popup-grey-bg" :scroll-y="true">
				<view class="grid-box u-p-l-30 u-p-r-30 u-p-b-30 u-m-t-80 u-m-b-30">
					<view class="head-title"><text>{{storeItemObj.store.name}}<text v-if="storeItemObj.state == '已取消'">(已撤销)</text></text></view>
					<view class="u-m-b-30"><text class="tips-txt">出库时间：{{storeItemObj.endtime}}</text></view>
					<goods-table :details="storeItem" :no-price="true"></goods-table>
					<view class="dashed-line"></view>
					<view class="msg-box u-p-t-10">
						<view class="item">
							<text class="label">回收种类：</text>
							<view class="text left">共{{ storeItemObj.details.length }}种</view>
						</view>
						<view class="item" v-if="storeItemObj.weight > 0">
							<text class="label">出库总重：</text>
							<view class="text left">{{storeItemObj.weight}}KG</view>
						</view>
						<view class="item" v-if="storeItemObj.quantity > 0">
							<text class="label">出库总数：</text>
							<view class="text left">{{storeItemObj.quantity}}件</view>
						</view>
					</view>
					<template v-if="storeItemObj.proves">
						<view class="u-p-t-30 u-p-b-30" v-if="storeItemObj.proves.length > 0">
							
							<view class="head-title u-m-b-30"><text>出库拍照</text></view>
							<view class="upload-box">
								<view class="item" v-for="(item,index) in storeItemObj.proves" :key="index">
									<u-image width="200rpx" height="200rpx" :src="utils.getPic(item)" @click="seePhoto(item)"></u-image>
								</view>
							</view>
						</view>
					</template>
					<view class="btn-group u-p-t-20">
						<view class="u-flex">
							<view class="u-flex-1" v-if="storeItemObj.iscancel"><u-button type="error" class="w-100" @click="cancelOrder(storeItemObj.id)">撤销</u-button></view>
						</view>
					</view>
				</view>
			</scroll-view>
		</u-popup> -->
		<!-- 取消订单 -->
		<u-popup v-model="show1" mode="center" border-radius="14" z-index="998" closeable>
			<view class="u-p-40" style="width: 600rpx;">
				<view class="u-p-t-30 u-p-b-15">请填写取消出库原因：</view>
				<view class="u-p-b-30">
					<u-input v-model="cancelForm.reason" type="textarea" :border="true" />
				</view>
				<u-button type="error" class="navbtn" @click="cancelOrder(0)">确定</u-button>
			</view>
		</u-popup>
	</view>
</template>

<script>
	import endOutboundList from '../../components/endOutboundList/endOutboundList.vue'
	import {
		mapState
	} from 'vuex';
	export default {
		components:{
			endOutboundList
		},
		data() {
			return {
				loading: true,
				id: 0,
				isoutbound: true,
				form: {
					packstation: {},
					packinorder:{},
					staff: {},
					deliverdetails: [],
					loadingproves: [],
					deliverproves: [],
					endproves: [],
					packdetails: [],
					amount: 0,
					store: {},
					packstation: {},
					proves:[],
					manufacturer:{
						id:0
					},
					supercargo:{},
					storeoutorder:[]
				},
				confirmForm: {
					orderid: 0,
					details: [
						// {
						// 	id: 0,
						// 	name: '杂纸',
						// 	weight: 10,
						// 	price: 9.9
						// }
					],
					total: 0
				},
				// 核实出库记录
				confirmOutOrderDetails: [],
				// 查看站点出库详情
				// showStoreDetails: false,
				// storeItem: [],
				// storeItemObj:{
				// 	details: [],
				// 	store:{
				// 		name: ''
				// 	}
				// },
				// 完结订单
				outOrderEndForm:{
					id: 0,
					details: [],
					proves: [],
					endTime: null
				},
				// 选择完结时间
				chooseTime: false,
				params: {
					year: true,
					month: true,
					day: true,
					hour: true,
					minute: true,
					second: false
				},
				piclist: [],
				// 取消订单
				show1: false,
				cancelForm: {
					id: 0,
					reason: ""
				},
				//弹窗显示小票详情
				showPackdetails: false,
				packdetails:{},
				// 出库清单汇总详情
				showTableDetails: false,
				tableDetails: {}
			};
		},
		computed: {
			...mapState({
				// userdetail: state => state.userdetail,
				header: state => state.Authorization,
				franchiseId: state => state.franchiseId,
				operatorId: state => state.operatorid
			}),
			...mapState('shop', {
				goodsDetails: state => state.goodsDetails,
			}),
			// 是否运营商管理员
			isOperatorAdmin(){
				try {
					return this.userdetail.bindinfo.operator.ismanager
				} catch (error) {
					//TODO handle the exception
					return false
				}
			},
			// 是否加盟商管理员
			isFranchiseAdmin(){
				try {
					return this.userdetail.bindinfo.operator.franchiselist.find((item)=>item.id == this.franchiseId).ismanager
				} catch (error) {
					//TODO handle the exception
					return false
				}
			}
		},
		watch:{
			goodsDetails(value){
				let confirmForm = {
					orderid: this.orderId,
					details: value
				}
				console.log('goodsDetails',confirmForm)
				// this.confirmChoose(confirmForm)
			}
		},
		onLoad(opt) {
			this.id = opt.id
			this.isoutbound = opt.isoutbound
			this.getDetails(this.id)
			this.$forceUpdate()
		},
		onPullDownRefresh() {
			this.getDetails(this.id).then(()=>{
				uni.stopPullDownRefresh(); //停止当前页面下拉刷新
			})
		},
		methods: {
			// 出库清单汇总详情
			getTableDetails(cell){
				this.tableDetails = cell
				this.showTableDetails = true
			},
			// 
			tableClick(cell){
				console.log('tableClick',cell)
				this.packdetails = cell
				this.showPackdetails = true
			},
			// 取消出库单
			cancelOrder(storeOutOrderId,content='您确定要撤销出库单吗?'){
				uni.showModal({
					title: '提示',
					content: content,
					success: (res) => {
						if (res.confirm) {
							let params = {
								id: this.id,
								storeOutOrderId: storeOutOrderId,
								reason: this.cancelForm.reason
							}
							this.$u.post('/Store/OutOrder/Cancel',params).then((res)=>{
								uni.showToast({
									icon: 'none',
									title: res.msg
								})
								this.show1 = false
								this.getDetails(this.id)
							})
						}
					}
				})
			},
			// 上传图片
			uploadSuccess(data, index, lists, name) {
				this.outOrderEndForm.proves = []
				lists.forEach((item,index)=>{
					this.outOrderEndForm.proves.push(item.response.datas.path)
				})
			},
			// 上传图片失败时处理
			uploadError(data, index, lists, name) {
				uni.showToast({
					icon: 'none',
					title: '提交失败，请重试'
				})
			},
			// 选择完结时间
			changeTime(e){
				console.log(e);
				this.outOrderEndForm.endTime = `${e.year}-${e.month}-${e.day} ${e.hour}:${e.minute}`
			},
			// 获取回执单列表
			getEndOutboundList(arr){
				this.outOrderEndForm.details = arr
			},
			// 确认完结
			confirmOutOrderEnd(){
				this.outOrderEndForm.id = this.id
				console.log('确认完结-confirmOutOrderEnd',this.outOrderEndForm)
				if(this.outOrderEndForm.details.length == 0){
					uni.showToast({
						title: '请核实出库记录',
						//将值设置为 success 或者直接不用写icon这个参数
						icon: "none",
						//显示持续时间为 2秒
						duration: 2000
					})
					return
				}
				if(!this.outOrderEndForm.endTime){
					uni.showToast({
						title: '请选择出库时间',
						//将值设置为 success 或者直接不用写icon这个参数
						icon: "none",
						//显示持续时间为 2秒
						duration: 2000
					})
					return
				}
				if(this.outOrderEndForm.proves.length == 0){
					uni.showToast({
						title: '请上传图片',
						//将值设置为 success 或者直接不用写icon这个参数
						icon: "none",
						//显示持续时间为 2秒
						duration: 2000
					})
					return
				}
				
				uni.showModal({
					title: '提示',
					content: '您确定要完结出库订单吗?',
					success: (res) => {
						if (res.confirm) {
							let form = {
								id: this.outOrderEndForm.id,
								// details: this.outOrderEndForm.details,
								details: [],
								proves: this.outOrderEndForm.proves,
								endTime: this.outOrderEndForm.endTime
							}
							
							this.outOrderEndForm.details.forEach((item)=>{
								form.details.push({
									productid: item.productid,
									grossweight: item.grossweight,
									tareweight: item.tareweight || 0,
									deductionweight: item.deductionweight || 0,
									deductionratio: item.deductionratio || 0,
									price: item.price,
									amount: item.amount,
									remarks: item.remarks
								})
							})
							console.log('出库订单完结提交参数：',form)
							this.$u.post('/Store/OutOrder/End', form).then((res) => {
								uni.showToast({
									icon: 'none',
									title: res.msg
								})
								// this.getDetails(this.id)
								uni.showModal({
									content: '结单成功',
									confirmText: '返回列表',
									showCancel: false,
									success: (res)=> {
										if (res.confirm) {
											console.log('用户点击确定');
											uni.redirectTo({
												url: '/pages/shop/outbound/list/list'
											})
										}
									}
								})
							})
						}
					}
				})
			},
			seePackdetails(item,index){
				this.packdetails = item
				this.packdetails.index = index
				// this.packdetails.img = this.fileURL + this.form.endproves[index]
				this.showPackdetails = true
			},
			// storeDetails(itemObj){
			// 	this.storeItem = []
			// 	this.storeItemObj = itemObj
			// 	this.storeItemObj.details.forEach((item)=>{
			// 		item.details.forEach((cell)=>{
			// 			this.storeItem.push({
			// 				"show": false,
			// 				"id": cell.productid,
			// 				"price": cell.sellprice,
			// 				"weight": cell.weight,
			// 				"amount": cell.sellamount,
			// 				"typeremarks": cell.remarks,
			// 				"allowedit": true,
			// 				"minprice": 0,
			// 				"highprice": 0,
			// 				"err": false,
			// 				"typenames": item.names,
			// 				"name": cell.productname,
			// 				"typeid": item.id,
			// 				"pic": item.icon,
			// 				"isweighing":cell.isweighing,
			// 				"on": true
			// 			})
			// 		})
			// 	})
			// 	this.showStoreDetails = true
			// },
			getDetails(id) {
				this.loading = true
				return this.$u.get('/Store/OutOrder/Details?id=' + id).then((res) => {
					this.form = res
					
					// 已出库时，汇总所有站点的出库数据
					// if(this.form.state == '已出库'){
						this.confirmForm.details = []
						// this.form.storeoutorder = this.form.storeoutorder.filter((c)=>c.state != '已取消')
						// this.form.storeoutorder = this.form.storeoutorder
						// this.form.storeoutorder.filter((c)=>c.state != '已取消').forEach((con)=>{
							this.form.details.forEach((item)=>{
								item.details.forEach((cell)=>{
									this.confirmForm.details.push({
										"show": false,
										"id": cell.productid,
										"price": cell.sellprice,
										"weight": cell.weight,
										"amount": cell.sellamount,
										"typeremarks": cell.remarks,
										"allowedit": true,
										"minprice": 0,
										"highprice": 0,
										"err": false,
										"typenames": item.names,
										"name": cell.productname,
										"isweighing": cell.isweighing,
										"typeid": item.id,
										"pic": item.icon,
										"isweighing":cell.isweighing,
										"on": true
									})
								})
							})
						// })
					// }
					
					// 已完结时，显示回执单的汇总
					if(this.form.state == '已完结'){
						this.confirmOutOrderDetails = []
						this.form.selldetails.forEach((item)=>{
							item.details.forEach((cell)=>{
								this.confirmOutOrderDetails.push({
									"show": false,
									"id": cell.productid,
									"price": cell.price,
									"weight": cell.netweight,
									"amount": cell.amount,
									"typeremarks": cell.remarks,
									"allowedit": true,
									"minprice": 0,
									"highprice": 0,
									"err": false,
									"typenames": item.names,
									"name": cell.productname,
									"isweighing": cell.isweighing,
									"typeid": item.id,
									"pic": item.icon,
									"isweighing":cell.isweighing,
									"on": true,
									"grossweight": cell.grossweight,
									"tareweight": cell.tareweight,
									"netweight": cell.netweight,
									"deductionweight": cell.deductionweight,
									"deductionratio": cell.deductionratio
								})
							})
						})
					}
					
					// 已取消时，显示已取消的出库清单
					// if(this.form.state == '已取消'){
					// 	this.confirmForm.details = []
					// 	// this.form.storeoutorder.forEach((con)=>{
					// 		this.form.details.forEach((item)=>{
					// 			item.details.forEach((cell)=>{
					// 				this.confirmForm.details.push({
					// 					"show": false,
					// 					"id": cell.productid,
					// 					"price": cell.sellprice,
					// 					"weight": cell.weight,
					// 					"amount": cell.sellamount,
					// 					"typeremarks": cell.remarks,
					// 					"allowedit": true,
					// 					"minprice": 0,
					// 					"highprice": 0,
					// 					"err": false,
					// 					"typenames": item.names,
					// 					"name": cell.productname,
					// 					"isweighing": cell.isweighing,
					// 					"typeid": item.id,
					// 					"pic": item.icon,
					// 					"isweighing":cell.isweighing,
					// 					"on": true
					// 				})
					// 			})
					// 		})
					// 	// })
					// }

					this.loading = false
					// this.setTotal()
				})
			},
			// 计算合计值
			// setTotal() {
			// 	this.confirmForm.total = 0
			// 	this.confirmForm.details.forEach((item) => {
			// 		this.confirmForm.total += Number(item.weight)
			// 	})
			// 	this.$forceUpdate()
			// },
			seePhoto(url) {
				uni.previewImage({
					current: 0,
					urls: [url]
				});
			},
			back(){
				uni.navigateBack()
			}
		}
	}
</script>

<style lang="scss" scoped>
	.input-text {
		border: 1px solid $u-border-color;
		border-radius: 5px;
		height: 70rpx;
		padding-right: 20rpx;
		padding-left: 20rpx;
		line-height: 70rpx;
		// width: 100%;
		input{
			height: 70rpx;
		}
	}
	.popup-grey-bg{
		background-color: #f7f7f7;
		max-height: 85vh;
	}
	.dashed-line{
		position: relative;
		left: -30rpx;
		width: 690rpx;
		border-bottom: 1px dashed #e4e7ed;
		&:after{
			content: '';
			width: 28rpx;
			height: 28rpx;
			border-radius: 28rpx;
			background-color: #f7f7f7;
			display: block;
			position: absolute;
			top: -14rpx;
			left: -14rpx;
			
		}
		&:before{
			content: '';
			width: 28rpx;
			height: 28rpx;
			border-radius: 28rpx;
			background-color: #f7f7f7;
			display: block;
			position: absolute;
			top: -14rpx;
			right: -14rpx;
		}
	}
	// .total {
	// 	margin-top: 20rpx;
	// 	text-align: right;
	// 	font-size: 24rpx;
	// 	// font-weight: bold;

		.total-price {
			color: $u-color-orange;
		}
	// }

	.bottom-box {
		.fixed-container {
			position: fixed;
			bottom: 0;
			background-color: #fff;
			width: 750rpx;
			padding-top: 0;
			height: 132rpx;
			z-index: 99;
			box-shadow: 0 0 16rpx #e7e7e7;
		}

		.fixed-placeholder {
			height: 132rpx;
			width: 750rpx;
			margin-top: 30rpx;
		}

		.total {
			line-height: 80rpx;
			padding-left: 30rpx;
			padding-right: 30rpx;
			margin: 0;
		}

		.btn-group {
			padding: 30rpx;

			.u-flex-1+.u-flex-1 {
				margin-left: 20rpx;
			}
		}
	}

	.w-100 {
		width: 100%;
	}
	
	.pack{
	    display: flex;
		padding: 0 0 0 10rpx;
	    // align-items: center;
	    .item{
			// width:40%;
			// border: 1px solid $u-border-color;
			display: flex;
			padding: 0 20rpx;
			// border-radius: 10rpx;
			min-height: 120rpx;
			margin-top: 0!important;
	        .name{
	            font-size: 36rpx;
				margin-bottom: 10rpx;
	        }
			.text{
			    color: $u-color-gray;
				font-size: 24rpx;
			}
	    }
		.left-con{
			display: flex;
			flex-direction: column;
			align-items: center;
			width: 20rpx;
			padding-bottom: 52rpx;
			.text{
				font-size: 24rpx;
				width: 40rpx;
				height: 40rpx;
				line-height: 40rpx;
				text-align: center;
				color: #fff;
				border-radius: 40rpx;
				background-color: $u-color-blue;
				&.in{
					background-color: $u-color-primary;
				}
				&.out{
					background-color: $u-color-orange;
				}
			}
			.border{
				border-left: 1px solid $u-border-color;
				flex: 1;
				width: 1px;
				margin: 10rpx 0;
			}
		}
	}
</style>
